package com.itheima.controller.menu;

import com.itheima.pojo.Menu;
import com.itheima.pojo.Result;
import com.itheima.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 获取全部菜品菜品列表
     * @return
     */
    @GetMapping
    public Result getAllMenu(){
        List<Menu> menus= menuService.getAllMenu();
        return Result.success(menus);
    }
    /**
     * 根据商家id获取全部菜品菜品列表
     * @return
     */
    @GetMapping("/list")
    public Result getMenuById(@RequestParam Integer uId){
        List<Menu> menus= menuService.getMenuById(uId);
        return Result.success(menus);
    }

    /**
     * 上传菜品到菜单
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Menu menu){
        menuService.add(menu);
        return Result.success();
    }
    /**
     * 修改菜品 1查询单个菜品，修改菜品内容
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Menu menu = menuService.getById(id);
        return  Result.success(menu);
    }
    // 修改菜品
    @PutMapping
    public  Result update(@RequestBody Menu menu){
        menuService.update(menu);
        return  Result.success();
    }




    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id ){
        menuService.delete(id);
        return  Result.success();
    }

}
